﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Express.ThirdParties.AliWulius
{
    public class AliWuliuManager : ThirdPartyWuliuManagerBase
    {
        public override WuliuQueryResult Query(string number, string type = null)
        {
            var instance = AliWuliuConfig.GetAliWuliuInstance();
            var result = instance.Qyery(number, type);

            var queryResult = new WuliuQueryResult();

            if(result.status != "200" && result.status != "0")
            {
                queryResult.Errors.Add($"阿里物流：{result.msg}");
            }
            else
            {
                queryResult.Number = result.result.number;
                queryResult.Type = result.result.type;
                queryResult.Items = result.result.list.Select(r => new WuliuQueryResult.QueryItem
                    {
                        Time = r.time,
                        Description = r.status
                    }).ToList();
            }

            return queryResult;
        }
    }
}
